package format

import (
	"github.com/pion/rtp"
	"gogs.smarteye.com/smarteye/gortc/pkg/format/rtpmpeg4video"
	"gogs.smarteye.com/smarteye/gortc/pkg/format/rtpps"
)

type PS struct{}

func (f *PS) unmarshal(_ *unmarshalContext) error {
	return nil
}

// Codec implements Format.
func (f *PS) Codec() string {
	return "PS"
}

// ClockRate implements Format.
func (f *PS) ClockRate() int {
	return 90000
}

// PayloadType implements Format.
func (f *PS) PayloadType() uint8 {
	return 96
}

// RTPMap implements Format.
func (f *PS) RTPMap() string {
	return "PS/90000"
}

// FMTP implements Format.
func (f *PS) FMTP() map[string]string {
	return nil
}

// PTSEqualsDTS implements Format.
func (f *PS) PTSEqualsDTS(*rtp.Packet) bool {
	return true
}

// CreateDecoder creates a decoder able to decode the content of the format.
func (f *PS) CreateDecoder() (*rtpps.Decoder, error) {
	d := &rtpps.Decoder{}

	err := d.Init()
	if err != nil {
		return nil, err
	}

	return d, nil
}

// CreateEncoder creates an encoder able to encode the content of the format.
func (f *PS) CreateEncoder() (*rtpps.Encoder, error) {
	e := &rtpps.Encoder{
		Encoder: &rtpmpeg4video.Encoder{
			PayloadType: f.PayloadType(),
		},
	}

	err := e.Init()
	if err != nil {
		return nil, err
	}

	return e, nil
}
